package com.yunlinker.asba.utils;

import android.os.Message;

import com.yunlinker.asba.imp.TimeCallback;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by mars on 2017/11/20.
 */

public class MyTimeTask {
    private Timer timer;
    private TimerTask task;
    public MyTimeTask(final TimeCallback timeCallback){
        timer = new Timer();
        try {
            task = new TimerTask() {
                public void run() {
                    timeCallback.callBack();
                }
            };
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void task( long duration){
        try {
            if(timer!=null&&task!=null)
            timer.schedule(task, duration);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void stopTask(){
        try {
            task.cancel();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
